<template>
    <div class="order-detail-container">
        <!-- 商品列表 -->
        <van-card
            v-for="item in order.goods"
            :key="item.id"
            :num="item.count"
            :price="item.price"
            :title="item.goods_name"
            :desc="item.goods_desc"
            :thumb="`${APIDomainName}${item.goods_img}`"
        />

        <!-- 订单备注 -->
        <van-cell title="订单备注" :value="order.note" label=""/>

        <!-- 配送信息 -->
        <van-cell
            title="配送服务"
            label="快递运输,工作日、双休日与节假日均可送货"
        />
        <!-- 收货地址 -->
        <van-cell title="收货地址">
            <template #label>
                <div>{{ order.address_name }} {{ order.address_phone }}</div>
                <div>{{ order.address_detail }}</div>
            </template>
        </van-cell>

        <!-- 费用信息 -->
        <van-cell title="商品金额" :value="`¥${order.amount}`"/>
        <van-cell title="运费" :value="`¥0.00`"/>
        <van-cell title="总价" :value="`¥${order.amount}`"/>

        <!-- 去支付按钮 -->
        <div v-if="order.status===0">
            <van-button type="primary" size="large" @click="onClickPay">去支付</van-button>
        </div>
        <div v-else-if="order.status===1">
            <van-button type="primary" size="large">已支付</van-button>
        </div>
        <div v-else-if="order.status=== 2">
            <van-button type="primary" size="large">已发货</van-button>
        </div>
        <div v-else-if="order.status===3">
            <van-button type="primary" size="large">已完成</van-button>
        </div>
        <div v-else-if="order.status===4">
            <van-button type="primary" size="large">已评价</van-button>
        </div>
    </div>
</template>

<script>
import {Button, Card, Cell, Dialog} from "vant";
import {getOrderDetailById} from "@/api/order.js";

export default {
    components: {
        [Button.name]: Button,
        [Card.name]: Card,
        [Cell.name]: Cell,
    },
    data() {
        return {
            order: {},
        };
    },
    props: ["id"],
    created() {
        this.getOrder();
    },
    methods: {
        async getOrder() {
            try {
                let result = await getOrderDetailById({id: this.id});
                console.log("show",result)
                if (result.code === 1) {
                    this.order = result.data;
                    console.log(this.order);
                } else if (result.code === 2) {
                    this.$router.push({name: "login"});
                } else {
                    throw result.msg;
                }
            } catch (error) {
                console.log(error)
                Dialog({title: "错误", message: error.msg});
                this.$router.back()
            }
        }, //=======================================

        onClickPay() {
            // this.$toast('还未实现....');
            this.$router.push(
                {
                    "name": "orderPay",
                    "params": {order: this.order}
                }
            )
        },
    },
};
</script>

<style lang="less" scoped>
.van-card__title {
    font-size: 14px;
}

.van-card__num {
    font-size: 14px;
    color: black;
}
</style>
